﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Text.RegularExpressions;

namespace blackhouse.Web.Controls.Weather {
    public class WeatherCity {

        #region Properties

        public string Name { get; private set; }
        internal string Link { get; private set; }

        public string WeatherImage { get; private set; }

        #endregion

        #region Constructors

        internal WeatherCity(string name, string link) {
            this.Name = name;
            this.Link = link;
        }

        #endregion

        #region Methods

        public void UpdateWeather() {
            XmlTextReader xmlReader = new XmlTextReader(this.Link);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlReader);
            string xmlContent = xmlDoc.ChildNodes[1].SelectSingleNode("channel/item/description").FirstChild.InnerText;
            this.read(xmlContent);

        }

        private void read(string content) {
            Regex rx = new Regex("<img src=\"(.*png)\"");
            Match imgMath = rx.Match(content);
            this.WeatherImage = imgMath.Groups[1].Value;
        }

        #endregion

    }
}